function ALOGsaveCombat() {
        var username = "C0mbatL0gger"; 
        var password = "vAd9Z7BEt6";

        if (localStorage.getItem ("po_alog_submit_logs") != "true") return;
        var done = localStorage.getItem ("po_alog_sent_combats");
        if (!done) done = "";
        
	function extractStr(source, begin, end) {
		var re = new RegExp(begin, "i");
		var i = source.search(re) + begin.length;
		var str = source.substring(i);
		re = new RegExp(end, "i");
		var j = str.search(re);
		return str.substring(0, j);
	}

	function trim(str) {
		var result = str.replace(/^\s+/, "");
		return result.replace(/\s+$/, "");
	}

	function prepareName(name) {
		var i = name.indexOf("(");
		return trim(i == -1 ? name : name.substr(0, i));
	}

	function append_input(form, name, value) {
		var input = document.createElement("input");
		input.type = "hidden";
		input.name = name;
		input.value = value;
		form.appendChild(input);
	}

	var cmbt = new Object();
	var str = document.location.search;
	cmbt.pid = str.substring(str.indexOf("=") + 1);
        if (done.indexOf (cmbt.pid) != -1) {
            return;
        }
	str = document.location.hostname;
	var universe = str.substring(0, str.indexOf("."));
	cmbt.universe = universe.charAt(0).toUpperCase() + universe.substring(1);

	var html = document.body.innerHTML;
	var elem = document.getElementById("report").previousSibling;
	while (elem && !elem.tagName)
		elem = elem.previousSibling;
	str = elem.innerHTML;
	var values = str.split(/<br>/i);
	cmbt.type = values[0];
        if (cmbt.type == "Ship vs NPC") return;
	cmbt.additional = values[1];

	//Get combat time in GMT
	var missionTime = new Date(values[values.length - 2].replace(/-/g, "/"));
	//alert (missionTime);
	var mtMill = missionTime.getTime();
	//alert(mtMill);
	var offset = missionTime.getTimezoneOffset() * 60000;
	//alert(offset);
	var ct = mtMill + offset;
	//alert(mtMill + '\n' + offset+ '\n' + ct);
	cmbt.when = ct;

	str = values[values.length - 1];
	var delim = null;
	if (str.search(/font/i) != -1) {
		delim = /<font.+font>/i;
		cmbt.outcome = extractStr(str, ">", "<");
	} else {
		var delims = ["disengaged from battle with", "was defeated by", "defeated"];
		var outcomes = ["disengaged", "was defeated by", "defeated"];
		for (var i = 0; i < delims.length; i++)
			if (str.indexOf(delims[i]) != -1) {
				delim = delims[i];
				cmbt.outcome = outcomes[i];
				break;
			}
	}
	values = str.split(delim);
	cmbt.attacker = prepareName(values[0]);
	cmbt.defender = prepareName(values[1]);
	str = extractStr(html, "confrontation in ", "]");
	values = str.split(" [");
	cmbt.sector = values[0];
	cmbt.coords = values[1];
	cmbt.data = extractStr(html, "cr = \"", "\"");

        var url = POgetServerUrl("combat_add.php", false);
        var query =
            "acc="+username
            + "&pwd="+password
            + "&pid="+cmbt.pid
            + "&type="+cmbt.type
            + "&when="+cmbt.when
            + "&universe="+cmbt.universe
            + "&sector="+cmbt.sector
            + "&coords="+cmbt.coords
            + "&attacker="+cmbt.attacker
            + "&defender="+cmbt.defender
            + "&outcome="+cmbt.outcome
            + "&additional="+cmbt.additional
            + "&data="+cmbt.data
            + "&userid="+POgetUserID ()
            + "&uname="+POgetUserName ()
            + "&vcode="+POgetValidationCode ();
        POajaxPost (url, "POST", query, null);
         
        var vals = done.split(";");
        if (vals.length > 50) {
            done = done.substr (done.indexOf (";")+1);
        }
        done += cmbt.pid+";";
        localStorage.setItem ("po_alog_sent_combats", done);
}

window.onload = setTimeout(function () {
    ALOGsaveCombat();
}, 10);